package main

import (
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promauto"
	"github.com/prometheus/client_golang/prometheus/promhttp"
	"log"
	"math"
	"net/http"
)

func main() {
	// 定义一个Summary类型的指标
	summary := promauto.NewSummary(prometheus.SummaryOpts{
		Name:       "pond_temperature_celsius",
		Help:       "The temperature of the frog pond.",
		Objectives: map[float64]float64{0.25: 0.001, 0.50: 0.001, 0.75: 0.001, 0.99: 0.001},
	})

	// Simulate some observations.
	for i := 0; i < 1000; i++ {
		summary.Observe(30 + math.Floor(120*math.Sin(float64(i)*0.1))/10)
	}

	// 指标上报的路径，可以通过该路径获取实时的监控数据
	http.Handle("/metrics", promhttp.Handler())
	log.Fatal(http.ListenAndServe(":8080", nil))
}
